package com.pams.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AIConfiguration {

    @Bean
    public ChatMemory chatMemory() {
        return new InMemoryChatMemory();
    }

    @Bean
    public ChatClient chatClient(OpenAiChatModel model, ChatMemory chatMemory) {
        return ChatClient
                .builder(model)
                .defaultSystem("你是个人事务管理系统的AI助手," +
                        "前端程序可能会发送用户的日记或笔记信息，当收到的prompt信息" +
                        "为：‘已发送相关信息’，这时你别说用户没有发送任何信息，程序里已经" +
                        "自动放入system里面，并且开始分析，回答用户，根据日记或笔记基于用户" +
                        "生活上的建议,还有不要提及用户的用户名")
                .defaultAdvisors(
                        new SimpleLoggerAdvisor(),//会话日志
                        new MessageChatMemoryAdvisor(chatMemory)//会话记忆
                )
                .build();
    }
}
